package com.edu.exam.entity.assessment.generation;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.edu.exam.enums.assessment.generation.PlanStatus;
import com.edu.exam.enums.assessment.generation.ReferenceType;
import com.edu.exam.enums.assessment.generation.ReferenceStrength;
import com.edu.exam.enums.assessment.generation.ValidationStatus;
import com.edu.exam.enums.assessment.generation.ApprovalStatus;
import com.edu.exam.enums.assessment.generation.SyncStatus;
import java.time.LocalDateTime;

/**
 * 考核方案关联实体类
 * 所属模块：B-05 考核计划管理模块
 * 对应数据库表：assessment_plan_reference
 *
 * <p>考核任务与考核方案的关联实体，记录生成任务时所依据的
 * 考核方案信息、匹配规则、应用参数等。确保任务生成的合规性
 * 和可追溯性。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Table(name = "assessment_plan_reference")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AssessmentPlanReference {

    /**
     * 关联ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 任务ID
     */
    @Column(name = "task_id", nullable = false)
    private Long taskId;

    /**
     * 任务编号
     */
    @Column(name = "task_code", length = 50)
    private String taskCode;

    /**
     * 考核方案ID
     */
    @Column(name = "assessment_plan_id", nullable = false)
    private Long assessmentPlanId;

    /**
     * 考核方案编号
     */
    @Column(name = "assessment_plan_code", length = 50)
    private String assessmentPlanCode;

    /**
     * 考核方案名称
     */
    @Column(name = "assessment_plan_name", length = 200)
    private String assessmentPlanName;

    /**
     * 考核方案版本
     */
    @Column(name = "assessment_plan_version", length = 20)
    private String assessmentPlanVersion;

    /**
     * 方案状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "plan_status", length = 20)
    private PlanStatus planStatus;

    /**
     * 关联类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "reference_type", length = 20, nullable = false)
    private ReferenceType referenceType;

    /**
     * 关联强度
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "reference_strength", length = 20)
    private ReferenceStrength referenceStrength;

    /**
     * 匹配度分数
     */
    @Column(name = "matching_score")
    private Integer matchingScore;

    /**
     * 匹配规则（JSON格式）
     */
    @Column(name = "matching_rules", columnDefinition = "TEXT")
    private String matchingRules;

    /**
     * 应用参数（JSON格式）
     */
    @Column(name = "application_parameters", columnDefinition = "TEXT")
    private String applicationParameters;

    /**
     * 方案内容摘要（JSON格式）
     */
    @Column(name = "plan_content_summary", columnDefinition = "TEXT")
    private String planContentSummary;

    /**
     * 应用的考核项目（JSON格式）
     */
    @Column(name = "applied_assessment_items", columnDefinition = "TEXT")
    private String appliedAssessmentPlanItems;

    /**
     * 应用的考核标准（JSON格式）
     */
    @Column(name = "applied_assessment_standards", columnDefinition = "TEXT")
    private String appliedAssessmentPlanStandards;

    /**
     * 应用的权重配置（JSON格式）
     */
    @Column(name = "applied_weight_configuration", columnDefinition = "TEXT")
    private String appliedWeightConfiguration;

    /**
     * 应用的评分规则（JSON格式）
     */
    @Column(name = "applied_scoring_rules", columnDefinition = "TEXT")
    private String appliedScoringRules;

    /**
     * 调整信息（JSON格式）
     */
    @Column(name = "adjustment_info", columnDefinition = "TEXT")
    private String adjustmentInfo;

    /**
     * 变更原因
     */
    @Column(name = "change_reason", length = 500)
    private String changeReason;

    /**
     * 验证状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "validation_status", length = 20)
    private ValidationStatus validationStatus;

    /**
     * 验证结果（JSON格式）
     */
    @Column(name = "validation_result", columnDefinition = "TEXT")
    private String validationResult;

    /**
     * 验证时间
     */
    @Column(name = "validation_time")
    private LocalDateTime validationTime;

    /**
     * 验证人ID
     */
    @Column(name = "validated_by")
    private Long validatedBy;

    /**
     * 验证人姓名
     */
    @Column(name = "validated_by_name", length = 100)
    private String validatedByName;

    /**
     * 审核状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "approval_status", length = 20)
    private ApprovalStatus approvalStatus;

    /**
     * 审核时间
     */
    @Column(name = "approval_time")
    private LocalDateTime approvalTime;

    /**
     * 审核人ID
     */
    @Column(name = "approved_by")
    private Long approvedBy;

    /**
     * 审核人姓名
     */
    @Column(name = "approved_by_name", length = 100)
    private String approvedByName;

    /**
     * 审核意见
     */
    @Column(name = "approval_comment", length = 1000)
    private String approvalComment;

    /**
     * 关联优先级
     */
    @Column(name = "reference_priority")
    private Integer referencePriority;

    /**
     * 是否为主要关联
     */
    @Column(name = "is_primary", nullable = false)
    private Boolean isPrimary;

    /**
     * 是否为模板关联
     */
    @Column(name = "is_template_reference")
    private Boolean isTemplateReference;

    /**
     * 是否需要更新
     */
    @Column(name = "requires_update")
    private Boolean requiresUpdate;

    /**
     * 最后同步时间
     */
    @Column(name = "last_sync_time")
    private LocalDateTime lastSyncTime;

    /**
     * 同步状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "sync_status", length = 20)
    private SyncStatus syncStatus;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    private Integer usageCount;

    /**
     * 最后使用时间
     */
    @Column(name = "last_used_time")
    private LocalDateTime lastUsedTime;

    /**
     * 删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 创建人ID
     */
    @Column(name = "created_by", nullable = false)
    private Long createdBy;

    /**
     * 创建人姓名
     */
    @Column(name = "created_by_name", length = 100)
    private String createdByName;

    /**
     * 更新人ID
     */
    @Column(name = "updated_by")
    private Long updatedBy;

    /**
     * 更新人姓名
     */
    @Column(name = "updated_by_name", length = 100)
    private String updatedByName;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

}

